<template>
  <!-- 加签dialog -->
  <el-dialog title="加签" v-model="visible" width="30%" destroy-on-close>
    <el-form
      :model="form"
      ref="dialogForm"
      :rules="rules"
      label-width="auto"
      label-position="right"
      class="noFlex"
    >
      <el-form-item label="审核人" prop="userIds">
        <el-select
          v-model="form.userIds"
          placeholder="请选择"
          style="width: 100%"
          multiple
          clearable
        >
          <el-option
            v-for="item in userList"
            :key="item.id"
            :label="item.username"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="加签说明">
        <el-input
          v-model="form.title"
          clearable
          type="textarea"
          rows="5"
          placeholder="请输入加签说明"
        ></el-input>
      </el-form-item>
      <el-form-item label="审批类型" prop="auditType">
        <el-radio-group v-model="form.auditType">
          <p style="width: 100%">
            <el-radio :label="1">按顺序依次审批</el-radio>
          </p>
          <p style="width: 100%">
            <el-radio :label="2"
              >会签 (可同时审批，每个人必须审批通过)</el-radio
            >
          </p>
          <p style="width: 100%">
            <el-radio :label="3">或签 (有一人审批通过即可)</el-radio>
          </p>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="加签类型" prop="addSignType">
        <el-radio-group v-model="form.addSignType">
          <p>
            <el-radio :label="1">前加签</el-radio>
          </p>
          <p style="margin-left: 20px">
            <el-radio :label="2">后加签</el-radio>
          </p>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="是否允许再加签"
        prop="isAddSign"
        v-if="authData.auditType == 1"
      >
        <el-radio-group v-model="form.isAddSign">
          <p>
            <el-radio :label="1">是</el-radio>
          </p>
          <p style="margin-left: 20px">
            <el-radio :label="0">否</el-radio>
          </p>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      form: {
        applicantId: null,//	申请人id
        correlationId: null,//关联主表id
        signUserId: null,//加签的审核人id,方便排序操作
        title: '',//加签说明
        addSignType: 1,//加签类型: 0，未加签，1，前加签，2、后加签
        auditType: 1,//	审核类型：1、依次顺序审核，2、会签（可同时审核），3、或签
        userIds: [],
        examineAuditUserIds: '',//加签人id集合
        isAddSign: 0,//	是否允许加签: 0不允许，1允许
        streamType: null
      },
      userIds: [],
      authData: {},//原审批数据
      visible: false,
      isSaveing: false,
      rules: {
        addSignType: [
          { required: true, message: '请选择加签类型', trigger: 'change', }
        ],
        auditType: [
          { required: true, message: '请选择审核类型', trigger: 'change', }
        ],
        userIds: [
          { required: true, message: '请选择加签人', trigger: 'change', }
        ]
      }
    }
  },
  props: {

  },
  mounted () {
    this.getUserList()
  },
  methods: {
    //显示
    open (data) {
      console.log(data)
      this.visible = true
      this.form.correlationId = data.correlationId
      this.form.streamType = data.streamType
      this.form.signUserId = data.examineUserId
      this.authData = data
      console.log(this.authData)
      let userInfo = this.$TOOL.data.get('USER_INFO')
      this.form.applicantId = userInfo.userId
    },
    // 获取所有用户列表
    async getUserList () {
      let res = await this.$API.user.getAdminList.get()
      if(res.data){
        this.userList = res.data
      }
    },
    submit () {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          let obj = { ...this.form }
          obj.examineAuditUserIds = this.form.userIds.join(',')
          delete obj.userIds
          this.isSaveing = true
          await this.$API.workflow.addSgin.post(obj)
          this.isSaveing = false
          this.visible = false
          this.$emit('update')
          this.$message.success("操作成功")
        }
      })
    },

  }
}
</script>

<style lang='scss' scoped>
.el-form .el-form-item {
  margin-bottom: 18px !important;
}
</style>
